package com.justnow.offer;

/**
 * @author justnow
 * Created on 2020-08-11
 * Description
 */
public class Solution52 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode node1 = headA, node2 = headB;

        while (node1 != node2) {
            if (node1 != null)
                node1 = node1.next;
            else
                node1 = headB;
            if (node2 != null)
                node2 = node2.next;
            else
                node2 = headA;
        }
        return node1;
    }

}

class ListNode {
    int val;
    ListNode next;
    ListNode (int val) {
        this.val = val;
    }
}
